package com.fkdx.dao.entity;

import com.github.pagehelper.Page;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.Data;

/**
 * @author: create by yuxg
 * @date:2022/5/4
 */
@Data
public class PageResult<R> {

    private Long total;
    private List<R> rows;

    public PageResult() {
    }

    public PageResult(Object list) {
        this.rows = (List<R>) list;
        if (list instanceof Page) {
            this.total = ((Page)list).getTotal();
        } else {
            this.total = (long)((List<R>)list).size();
        }

    }

    public <T> PageResult(List<T> list, Function<T, R> function) {
        if (list instanceof Page) {
            this.total = ((Page)list).getTotal();
        } else {
            this.total = (long)list.size();
        }
        this.rows = list.stream().map(function::apply).collect(Collectors.toList());
    }

}
